var e = require;
var t = module;
var o = exports;
Object.defineProperty(o, "__esModule", {value: !0});
var n = e("BaseModuleUI"),
    a = e("GlobalParams"),
    i = e("AudioManager"),
    r = e("Game"),
    s = e("RoleSoldierInfo"),
    l = e("UIManager"),
    c = e("ShopViewUI"),
    d = e("AD"),
    h = e("GetZsViewUI"),
    _ = cc._decorator,
    u = _.ccclass,
    p = _.property,
    m = (function (e) {
        function t() {
            var t = (null !== e && e.apply(this, arguments)) || this;
            return (
                (t.role_ske_node = null),
                (t.role_name_label = null),
                (t.use_btn = null),
                (t.uiManager = null),
                (t.main_role_index = 0),
                t
            );
        }
        return (
            __extends(t, e),
            (t.prototype.initView = function () {
                (this.uiManager = cc.find("UIManager").getComponent(l.default)),
                    (this.main_role_index = a.GlobalParams.GameHeroIndex.indexOf(
                        a.GlobalParams.playerSkinInfo.value.use[0]
                    )),
                    this.showRoleSke();
            }),
            (t.prototype.OnClick = function (t) {
                switch ((e.prototype.OnClick.call(this, t), t.node.name)) {
                    case "right_btn":
                        this.main_role_index++,
                            (this.main_role_index =
                                this.main_role_index > a.GlobalParams.GameHeroIndex.length - 1
                                    ? 0
                                    : this.main_role_index),
                            this.showRoleSke();
                        break;
                    case "left_btn":
                        this.main_role_index--,
                            (this.main_role_index =
                                this.main_role_index < 0
                                    ? a.GlobalParams.GameHeroIndex.length - 1
                                    : this.main_role_index),
                            this.showRoleSke();
                        break;
                    case "use_btn":
                        this.buyRoleSke();
                }
            }),
            (t.prototype.showRoleSke = function () {
                var e = this,
                    t = r.default.shop_role_info[a.GlobalParams.GameHeroIndex[this.main_role_index]];
                (this.use_btn.children[0].active = 0 == t.type),
                    (this.use_btn.children[1].active = 1 == t.type),
                    (this.use_btn.children[4].active = 2 == t.type),
                    (this.use_btn.children[5].active = 3 == t.type),
                    (this.use_btn.children[3].active = 4 == t.type),
                    (this.use_btn.children[0].children[1].getComponent(cc.Label).string =
                        this.use_btn.children[1].children[1].getComponent(cc.Label).string =
                            "" + t.num * t.discount),
                    (this.use_btn.children[2].active = 1 != t.discount),
                    (this.use_btn.children[2].getComponent(cc.Label).string = "" + t.num),
                    this.uiManager.getRoleSkele(t.id, function (t) {
                        (e.role_ske_node.skeletonData = t), e.role_ske_node.setAnimation(0, "battle_idle", !0);
                    }),
                    (this.use_btn.active = -1 == a.GlobalParams.playerSkinInfo.value.have.hero.indexOf(t.id)),
                    (this.role_name_label.string = "" + s.default.Role_info[t.id].C_Name);
            }),
            (t.prototype.buyRoleSke = function () {
                var e = this,
                    t = r.default.shop_role_info[a.GlobalParams.GameHeroIndex[this.main_role_index]],
                    o = function () {
                        var o = a.GlobalParams.playerSkinInfo.value;
                        (o.use[0] = t.id),
                            o.have.hero.push(t.id),
                            (a.GlobalParams.playerSkinInfo.value = o),
                            cc.find("UIManager").getComponent(l.default).showPopup("ObtainHeroTipView"),
                            e.showRoleSke();
                    },
                    n = a.GlobalParams.PlayerInfo.value;
                if (this.use_btn.children[0].active) {
                    var s = t.num * t.discount;
                    n.coin >= s
                        ? (cc.find("UIManager").getComponent(l.default).consumeCoinAndZs(0, s), o())
                        : cc
                              .find("UIManager")
                              .getComponent(l.default)
                              .showPopup("ShopViewUI", function (e) {
                                  e.getComponent(c.default).showShopTypeInfo("shop_coin_btn");
                              });
                } else if (this.use_btn.children[1].active) {
                    var _ = t.num * t.discount;
                    n.zs >= _
                        ? (cc.find("UIManager").getComponent(l.default).consumeCoinAndZs(1, _), o())
                        : cc
                              .find("UIManager")
                              .getComponent(l.default)
                              .showPopup("GetZsViewUI", function (e) {
                                  e.getComponent(h.default).showPopupInfoView(0);
                              });
                } else
                    this.use_btn.children[3].active
                        ? d.default.getInstance().showVideo(function (e) {
                              i.default.playGameBGM(), e == d.ResultEnum.Success && o();
                          })
                        : this.use_btn.children[4].active
                        ? this.uiManager.showPopup("SigninViewUI")
                        : this.use_btn.children[5].active && this.uiManager.showPopup("LuckyBoxViewUI");
            }),
            __decorate([p(sp.Skeleton)], t.prototype, "role_ske_node", void 0),
            __decorate([p(cc.Label)], t.prototype, "role_name_label", void 0),
            __decorate([p(cc.Node)], t.prototype, "use_btn", void 0),
            __decorate([u], t)
        );
    })(n.default);
o.default = m;
